package com.team12.hotel404.service.serviceImpl;

import com.team12.hotel404.domain.Role;
import com.team12.hotel404.domain.RoleExample;
import com.team12.hotel404.mapper.RoleMapper;
import com.team12.hotel404.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    /**
     * list all
     *
     * @return list of role
     */
    @Override
    public List<Role> listAllRole() {
        return roleMapper.selectByExample(new RoleExample());
    }

    /**
     * update role
     *
     * @param role role对象
     */
    @Override
    public void updateRoleInfo(Role role) {
        roleMapper.updateByPrimaryKeySelective(role);
    }

    /**
     * insert role
     * @param role role对象
     */
    @Override
    public void insertRole(Role role) {
        roleMapper.insert(role);
    }

    /**
     * delete role
     * @param id role id
     */
    @Override
    public void deleteRole(Integer id) {
        roleMapper.deleteByPrimaryKey(id);
    }

    /**
     * find role by id
     * @param id role id
     */
    @Override
    public void findRoleById(Integer id) {
        roleMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Role> findRoleByUserId(Integer id) {
        return roleMapper.findRoleByUserId(id);
    }
}
